package com.shuidi.oilactivity.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.shuidi.oilactivity.R;
import com.shuidi.oilactivity.bean.Customer;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class CustomerActivity extends BaseActivity {

    @BindView(R.id.top_left_btn)
    ImageButton topLeftBtn;
    @BindView(R.id.title_bar)
    TextView titleBar;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.layout1)
    RelativeLayout layout1;
    @BindView(R.id.layout2)
    RelativeLayout layout2;
    @BindView(R.id.all_number)
    TextView allNumber;
    @BindView(R.id.layout3)
    RelativeLayout layout3;

    public static CustomerActivity customerActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer);
        ButterKnife.bind(this);
        customerActivity = this;
        allCustomerNumber();

    }

    @OnClick({R.id.top_left_btn, R.id.layout1, R.id.layout2,R.id.layout3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.top_left_btn:
                finish();
                break;
            case R.id.layout1:
                Toast.makeText(CustomerActivity.this, "暂未开始该活动", Toast.LENGTH_SHORT).show();
                break;
            case R.id.layout2:
                Intent intent = new Intent(CustomerActivity.this, AddCustomerActivity.class);
                startActivity(intent);
                break;
            case R.id.layout3:
                Intent intent3 = new Intent(CustomerActivity.this,AllCustomerActivity.class);
                startActivity(intent3);
                break;
        }
    }

    protected void allCustomerNumber(){

        BmobQuery<Customer> bmobQuery = new BmobQuery<Customer>();
        bmobQuery.addQueryKeys("objectId");
        bmobQuery.findObjects(new FindListener<Customer>() {
            @Override
            public void done(List<Customer> list, BmobException e) {
                if(e==null){
                    allNumber.setText(list.size()+"人");
                }else{
                    Log.i("bmob","失败："+e.getMessage()+","+e.getErrorCode());
                }
            }
        });
    }
}
